package cn.zb.entity;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;

// 文档实体 对应ES的文档
@NoArgsConstructor
@Data
@Document(indexName = "hotel",shards = 1,replicas = 0)
public class TbHotelDoc {
    @Id // 对应文档id
    @Field(type = FieldType.Keyword)
    private Long id;
    // type映射的文档属性类型   analyzer指定分词器
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String name;
    @Field(type = FieldType.Text,analyzer = "ik_max_word")
    private String address;
    @Field(type = FieldType.Double)
    private Integer price;
    @Field(type = FieldType.Integer)
    private Integer score;
    @Field(type = FieldType.Keyword)
    private String brand;
    @Field(type = FieldType.Keyword)
    private String city;
    @Field(type = FieldType.Keyword)
    private String starName;
    @Field(type = FieldType.Text,analyzer = "ik_smart")
    private String business;
    /**
     * //map lat 纬度,lon 经度
     * "location": { "lat": 41.12, "lon": -71.34 }
     * //字符串,逗号分隔 纬度,经度
     * { "location": "41.12,-71.34" }
     * //地理哈希
     * { "location": "drm3btev3e86" }
     * //数组[经度, 纬度]
     * { "location": [ -71.34, 41.12 ] }
     */
    @GeoPointField
    private String location; // 这里使用字符串拼接经纬度

    @Field(type = FieldType.Keyword,index = false)
    private String pic;

    public TbHotelDoc(TbHotel hotel){
        this.id = hotel.getId();
        this.name = hotel.getName();
        this.address = hotel.getAddress();
        this.price = hotel.getPrice();
        this.score = hotel.getScore();
        this.brand = hotel.getBrand();
        this.city = hotel.getCity();
        this.starName = hotel.getStarName();
        this.business = hotel.getBusiness();
        this.pic = hotel.getPic();
        this.location = hotel.getLatitude()+","+hotel.getLongitude();
    }
}